<h2>DESCRIPTION</h2>

<em>v.lidar.edgedetection</em> is the first of three steps to filter
LiDAR data. The filter aims to recognize and extract attached and 
detached object (such as buildings, bridges, power lines,  trees, etc.) 
in order to create a Digital Terrain Model. 

<p>
In particular, this module detects the edge of each single feature over 
the terrain surface of a LIDAR point surface. First of all, a bilinear 
spline interpolation with a Tychonov regularization parameter is 
performed. The gradient is minimized and the low Tychonov regularization 
parameter brings the interpolated functions as close as possible to the 
observations. Bicubic spline interpolation with Tychonov regularization 
is then performed. However, now the curvature is minimized and the 
regularization parameter is set to a high value. For each point, an 
interpolated value is computed from the bicubic surface and an interpolated 
gradient is computed from the bilinear surface. At each point the gradient 
magnitude and the direction of the edge vector are calculated, and the 
residual between interpolated and observed values is computed. Two thresholds 
are defined on the gradient, a high threshold <b>tgh</b> and a low one 
<b>tgl</b>. For each point, if the gradient magnitude is greater than or 
equal to the high threshold and its residual is greater than or equal to 
zero, it is labeled as an EDGE point. Similarly a point is labeled as 
being an EDGE point if the gradient magnitude is greater than or equal to 
the low threshold, its residual is greater than or equal to zero, and the 
gradient to two of eight neighboring points is greater than the high 
threshold. Other points are classified as TERRAIN.

<p>
The length (in mapping units) of each spline step is defined by 
<b>ew_step</b> for the east-west direction and <b>ns_step</b> for the 
north-south direction.

<p>
The output will be a vector map in which points has been classified as 
TERRAIN, EDGE or UNKNOWN. This vector map should be the input of 
<em><a href="v.lidar.growing.html">v.lidar.growing</a></em> module.

<!-- TODO: review how it is with layers and cats -->
<h2>NOTES</h2>

In this module, an external table will be created which will be useful for 
the next module of the procedure of LiDAR data filtering. In this table 
the interpolated height values of each point will be recorded. Also points 
in the output vector map will be classified as:

<div class="code"><pre>
TERRAIN (cat = 1, layer = 1)
EDGE (cat = 2, layer = 1)
UNKNOWN (cat = 3, layer = 1)
</pre></div>

The final result of the whole procedure (<em>v.lidar.edgedetection</em>,
<em><a href="v.lidar.growing.html">v.lidar.growing</a></em>,
<em><a href="v.lidar.correction.html">v.lidar.correction</a></em>)
will be a point classification in four categories:

<div class="code"><pre>
TERRAIN SINGLE PULSE (cat = 1, layer = 2)
TERRAIN DOUBLE PULSE (cat = 2, layer = 2)
OBJECT SINGLE PULSE (cat = 3, layer = 2)
OBJECT DOUBLE PULSE (cat = 4, layer = 2)
</pre></div>

<h2>EXAMPLES</h2>

<h3>Basic edge detection</h3>

<div class="code"><pre>
# last return points
v.lidar.edgedetection input=vector_last output=edge ew_step=8 ns_step=8 lambda_g=0.5
</pre></div>

<h3>Complete workflow</h3>

<div class="code"><pre>
# region settings (using an existing raster)
g.region raster=elev_lid792_1m

# import
v.in.lidar -tr input=points.las output=points
v.in.lidar -tr input=points.las output=points_first return_filter=first

# detection
v.lidar.edgedetection input=points output=edge ew_step=8 ns_step=8 lambda_g=0.5
v.lidar.growing input=edge output=growing first=points_first
v.lidar.correction input=growing output=correction terrain=only_terrain

# visualization of selected points
# zoom somewhere first, to make it faster
d.rast map=orthophoto
d.vect map=correction layer=2 cats=2,3,4 color=red size=0.25
d.vect map=correction layer=2 cats=1 color=0:128:0 size=0.5

# interpolation (this may take some time)
v.surf.rst input=only_terrain elevation=terrain

# get object points for 3D visualization
v.extract input=correction layer=2 cats=2,3,4 output=objects
</pre></div>
<!-- TODO: the selection of layer and cats might be not completely correct -->
<!--
las: http://ncsu-osgeorel.github.io/uav-lidar-analytics-course/
orthophoto: USGS WMS
mogrify -resize 600x v_lidar_edgedetection.png
optipng -o5 v_lidar_edgedetection.png

m.nviz.image elevation_map=terrain -a mode=fine resolution_fine=1 color=191:191:191 \
    vpoint=objects vpoint_width=2 vpoint_color=255:0:0 vpoint_size=0 \
    vpoint_marker=sphere vpoint_position=0,0,0 vpoint_layer=1,1 \
    position=0.66,0.51 height=139 perspective=20 twist=0 zexag=2.000000 focus=146,96,123 \
    output=nviz_output format=ppm size=796,528
-->
<center>
    <img src="v_lidar_edgedetection.png">
    <p><em>Figure 1: Example output from complete workflow (red: objects, green: terrain)</em></p>
</center>

<center>
    <img src="v_lidar_edgedetection_objects.png">
    <p><em>
        Figure 2: 3D visualization of filtered object points (red)
        and terrain created from terrain points (gray)
    </em></p>
</center>

<h2>REFERENCES</h2>

<ul>
<li>Antolin, R. et al., 2006. Digital terrain models determination by LiDAR 
technology: Po basin experimentation. Bolletino di Geodesia e Scienze 
Affini, anno LXV, n. 2, pp. 69-89.</li>
<li>Brovelli M. A., Cannata M., Longoni U.M., 2004. LIDAR Data Filtering and 
DTM Interpolation Within GRASS, Transactions in GIS, April 2004,  vol. 8, 
iss. 2, pp. 155-174(20), Blackwell Publishing Ltd.</li>
<li>Brovelli M. A., Cannata M., 2004. Digital Terrain model reconstruction in 
urban areas from airborne laser scanning data: the method and an  example 
for Pavia (Northern Italy). Computers and Geosciences 30 (2004) pp.325-331</li>
<li>Brovelli M. A. and Longoni U.M., 2003. Software per il filtraggio di dati 
LIDAR, Rivista dell'Agenzia del Territorio, n. 3-2003, pp. 11-22 (ISSN 1593-2192).</li>
<li>Brovelli M. A., Cannata M. and Longoni U.M., 2002. DTM LIDAR in area urbana, 
Bollettino SIFET N.2, pp. 7-26.</li>
<li>Performances of the filter can be seen in the
<a href="http://www.itc.nl/isprswgIII-3/filtertest/MainDoc.htm">ISPRS WG III/3 Comparison of Filters</a> 
report by Sithole, G. and Vosselman, G., 2003.</li>
</ul>

<h2>SEE ALSO</h2>

<em>
<a href="v.lidar.growing.html">v.lidar.growing</a>,
<a href="v.lidar.correction.html">v.lidar.correction</a>,
<a href="v.surf.bspline.html">v.surf.bspline</a>,
<a href="v.surf.rst.html">v.surf.rst</a>,
<a href="v.in.lidar.html">v.in.lidar</a>,
<a href="v.in.ascii.html">v.in.ascii</a>
</em>

<h2>AUTHORS</h2>

Original version of program in GRASS 5.4:
<br>
Maria Antonia Brovelli, Massimiliano Cannata, Ulisse Longoni and Mirko Reguzzoni
<br><br>
Update for GRASS 6.X:
<br>
Roberto Antolin and Gonzalo Moreno

<!--
<p>
<i>Last changed: $Date$</i>
-->
